/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package BL;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 *
 * @author sundas
 */
@Entity
@Table(name = "orderlineitem", catalog = "newPurchase", schema = "", uniqueConstraints = {@UniqueConstraint(columnNames = {"productNumber", "orderId", "orderLineId"})})
@NamedQueries({@NamedQuery(name = "Orderlineitem.findAll", query = "SELECT o FROM Orderlineitem o"), @NamedQuery(name = "Orderlineitem.findByProductNumber", query = "SELECT o FROM Orderlineitem o WHERE o.orderlineitemPK.productNumber = :productNumber"), @NamedQuery(name = "Orderlineitem.findByOrderLineId", query = "SELECT o FROM Orderlineitem o WHERE o.orderlineitemPK.orderLineId = :orderLineId"), @NamedQuery(name = "Orderlineitem.findByProductQty", query = "SELECT o FROM Orderlineitem o WHERE o.productQty = :productQty"), @NamedQuery(name = "Orderlineitem.findByOrderId", query = "SELECT o FROM Orderlineitem o WHERE o.orderlineitemPK.orderId = :orderId")})
public class Orderlineitem implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected OrderlineitemPK orderlineitemPK;
    @Column(name = "productQty")
    private Integer productQty;
    @JoinColumn(name = "productNumber", referencedColumnName = "productNumber", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Product product;
    @JoinColumn(name = "orderId", referencedColumnName = "orderId", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Prodorder prodorder;

    public Orderlineitem() {
    }

    public Orderlineitem(OrderlineitemPK orderlineitemPK) {
        this.orderlineitemPK = orderlineitemPK;
    }

    public Orderlineitem(int productNumber, int orderLineId, int orderId) {
        this.orderlineitemPK = new OrderlineitemPK(productNumber, orderLineId, orderId);
    }

    public OrderlineitemPK getOrderlineitemPK() {
        return orderlineitemPK;
    }

    public void setOrderlineitemPK(OrderlineitemPK orderlineitemPK) {
        this.orderlineitemPK = orderlineitemPK;
    }

    public Integer getProductQty() {
        return productQty;
    }

    public void setProductQty(Integer productQty) {
        this.productQty = productQty;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public Prodorder getProdorder() {
        return prodorder;
    }

    public void setProdorder(Prodorder prodorder) {
        this.prodorder = prodorder;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (orderlineitemPK != null ? orderlineitemPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Orderlineitem)) {
            return false;
        }
        Orderlineitem other = (Orderlineitem) object;
        if ((this.orderlineitemPK == null && other.orderlineitemPK != null) || (this.orderlineitemPK != null && !this.orderlineitemPK.equals(other.orderlineitemPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "DB.Orderlineitem[orderlineitemPK=" + orderlineitemPK + "]";
    }

}
